package com.itheima.json;

import com.alibaba.fastjson.JSON;

public class FastJsonDemo {
    public static void main(String[] args){
        //1.将Java对象的字符串转为JSON字符串
        User user =new User();
        user.setId(11);
        user.setUsername("zhangsan");
        user.setPassword("123");

        String jsonString = JSON.toJSONString(user);
        System.out.println(jsonString);


        //2.将JSON字符串转为Java对象
        User u = JSON.parseObject("{\"id\":11,\"password\":\"123\",\"username\":\"zhangsan\"}", User.class);
        System.out.println(u);


    }
}
